Event Attributes | |
---|---|
<widget |
The widget which generated this event. This attribute is set for all events. |
x, y | The current mouse position, in pixels. |
x_root, y_root | The current mouse position relative to the upper left corner of the screen, in pixels. |
keysym | The key symbol (keyboard events only). |
keycode | The key code (keyboard events only). |
Methods: | |
---|---|
<Button-1> | left mouse button click |
<Button-2> | middle mouse button click |
<Button-3> | right mouse button click |
<ButtonPress-1> | left mouse button Press |
<ButtonPress-2> | middle mouse button Press |
<ButtonPress-3> | right mouse button Press |
<ButtonRelease-1> | left mouse button Release |
<ButtonRelease-2> | middle mouse button Release |
<ButtonRelease-3> | right mouse button Release |
<Motion> | mouse movements |
<B1-Motion> | mouse drag pressing left button |
<B2-Motion> | mouse drag pressing middle button |
<B3-Motion> | mouse drag pressing right button |
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() self.geometry("500x300") self.bind("",self.showpos) def showpos(self,e): data=str(e.x) +" : "+str(e.y) self.title(data) frm=MyFrame() frm.mainloop()
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() self.can=Canvas(self,width=500,height=400,bg="white") self.can.pack() self.can.bind("",self.show) def show(self,e): lst=[e.x-50,e.y-50,e.x+50,e.y+50] self.can.create_oval(lst,outline="red",fill="yellow",width=5) frm=MyFrame() frm.mainloop()
from tkinter import * win = Tk() win.geometry('500x400') def show(e): info=[e.x-15,e.y-15,e.x+15,e.y+15] can.create_oval(info,fill="yellow",outline="red") can=Canvas(win) can.place(relwidth=1.0,relheight=1.0) can.bind('<B1-Motion>', show) win.mainloop()